package com.itheima.controller;


import com.itheima.domain.FlashPromotionProductRelation;
import com.itheima.manager.SmsFlashPromotionProductRelationManager;
import com.itheima.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/flashProductRelation")
public class SmsFlashPromotionProductRelationController {
    @Autowired
    SmsFlashPromotionProductRelationManager relationManager;

    //分页查询不同场次关联及商品信息
    @GetMapping("/list")
    public Result list(
            @RequestParam(defaultValue = "1")Integer pageNum,
            @RequestParam(defaultValue = "5")Integer pageSize,
            Integer flashPromotionId,
            Integer flashPromotionSessionId){
        return relationManager.list(pageNum,pageSize,flashPromotionId,flashPromotionSessionId);
    }
    //批量选择商品添加关联
    @PostMapping("/create")
    public Result create(@RequestBody List<FlashPromotionProductRelation> relationList){
        return relationManager.create(relationList);
    }

    //删除关联
    @PostMapping("/delete/{id}")
    public Result delete(@PathVariable Integer id){
        return relationManager.delete(id);
    }

    //修改关联信息
    @PostMapping("/update/{id}")
    public Result update(@PathVariable Long id,@RequestBody FlashPromotionProductRelation relation){
        return relationManager.update(id,relation);
    }

    //获取管理商品促销信息
    @GetMapping("/{id}")
    public Result selectById(@PathVariable Integer id){
        return relationManager.selectById(id);
    }


}
